package com.cykj.eurekaclient.service.impl;

import com.cykj.eurekaclient.bean.*;
import com.cykj.eurekaclient.mapping.BusMapper;
import com.cykj.eurekaclient.service.BusService;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BusServiceImpl implements BusService {
    @Autowired
    private BusMapper busMapper;

    @Override
    public int selectAllBus(String cityid, String licensePlate, String maintainer, long state) {
        return busMapper.selectAllBus(cityid, licensePlate, maintainer, state);
    }

    @Override
    public List<Bus> selectBusList(RowBounds rowBounds, String cityid, String licensePlate, String maintainer, long state) {
        return busMapper.selectBusList(rowBounds, cityid, licensePlate, maintainer, state);
    }

    @Override
    public boolean addBus(int cityid, int fettleId, String registrationTime, String licensePlate) {
        boolean flap = false;
        try {
            busMapper.addBus(cityid, fettleId, registrationTime, licensePlate);
            flap = true;
        } catch (Exception e) {
            e.printStackTrace();
            flap = false;
        }
        return flap;
    }

    @Override
    public boolean updateBus(int fettlerId, int state, String licensePlate, long id) {
        boolean flap = false;
        try {
            busMapper.updateBus(fettlerId, state, licensePlate, id);
            flap = true;
        } catch (Exception e) {
            e.printStackTrace();
            flap = false;
        }
        return flap;
    }

    @Override
    public boolean delBus(long id) {
        boolean flap = false;
        try {
            busMapper.delBus(id);
            flap = true;
        } catch (Exception e) {
            e.printStackTrace();
            flap = false;
        }
        return flap;
    }

    @Override
    public boolean stopBus(long id, int busState) {
        boolean flap = false;
        try {
            busMapper.stopBus(id, busState);
            flap = true;
        } catch (Exception e) {
            e.printStackTrace();
            flap = false;
        }
        return flap;
    }

    @Override
    public int selectMaintainNum(String cityId, String licensePlate) {
        return busMapper.selectMaintainNum(cityId, licensePlate);
    }

    @Override
    public List<Bus> selectMaintaining(String cityId) {
        return busMapper.selectMaintaining(cityId);
    }

    @Override
    public List<Bus> selectAllMaintain(RowBounds rowBounds, String cityId, String licensePlate) {
        return busMapper.selectAllMaintain(rowBounds, cityId, licensePlate);
    }

    @Override
    public List<RouteInfo> selectClasses() {
        return busMapper.selectClasses();
    }

    @Override
    public List<RouteTimeNode> getBeginJourney(String routeName) {
        return busMapper.getBeginJourney(routeName);
    }

    @Override
    public boolean addCarArrange(String beginTime, long routeId, long busId) {
        boolean flap = false;
        try {
            busMapper.addCarArrange(beginTime, routeId, busId);
            flap = true;
        } catch (Exception e) {
            e.printStackTrace();
            flap = false;
        }
        return flap;
    }

    @Override
    public List<StationInfo> getBusRoute(String routeName) {
        return busMapper.getBusRoute(routeName);
    }

    @Override
    public long getBusRouteId(String routeName) {
        return busMapper.getBusRouteId(routeName);
    }

    @Override
    public boolean carReArrange(long id, long busId) {
        boolean flap = false;
        try {
            busMapper.carReArrange(id, busId);
            flap = true;
        } catch (Exception e) {
            e.printStackTrace();
            flap = false;
        }
        return flap;
    }

    @Override
    public int SelectBusState(String busState) {
        return busMapper.SelectBusState(busState);
    }

    @Override
    public int selectCity(String cityname) {
        return busMapper.selectCity(cityname);
    }

    @Override
    public int selectFettle(String maintainer) {
        return busMapper.selectFettle(maintainer);
    }

    @Override
    public List<StationInfo> selStationName(String searchInfo) {
        List<StationInfo> stationInfos = busMapper.selStationName(searchInfo);
        for (StationInfo stationInfo : stationInfos) {
            System.out.println("站点名字：" + stationInfo.getName());
        }
        return stationInfos;
    }

    @Override
    public List<String> selRouteName(String routeName) {
        List<String> a = busMapper.selRouteName(routeName);
        return a;
    }

    @Override
    public List<StationInfo> getStationListMY(String district) {
        List<StationInfo> stationInfos = busMapper.getStationListMY(district);
        return stationInfos;
    }

    @Override
    public List<RouteInfo> getRideScheme(String startStationName, String endStationName) {

        List<RouteInfo> routeInfos = busMapper.getRideScheme(startStationName, endStationName);
        return routeInfos;
    }

    @Override
    public List<RouteInfo> stationInRouteAll(String startStationName) {
        List<RouteInfo> routeInfos = busMapper.stationInRouteAll(startStationName);
        return routeInfos;
    }

    @Override
    public StationInfo useNameGetStationInfo(String stationName) {
        StationInfo stationInfo = busMapper.useNameGetStationInfo(stationName);
        return stationInfo;
    }

    @Override
    public List<StationInfo> interceptStation(String routeName, long upStationSequence, long stopStationSequence) {
        List<StationInfo> stationInfos = busMapper.interceptStation(routeName, upStationSequence, stopStationSequence);
        return stationInfos;
    }

    @Override
    public List<StationInfo> backInterceptStation(String routeName, long stopStationSequence, long upStationSequence) {
        List<StationInfo> stationInfos = busMapper.backInterceptStation(routeName, stopStationSequence, upStationSequence);
        return stationInfos;
    }


}
